package dao.impl;

import bean.Bean2;
import dao.mapper.Bean2Mapper;
import wrap.WrapBean2;
import dao.Bean2DAO;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class Bean2DAOImpl implements Bean2DAO {
    private SqlSession session;
    private Bean2Mapper mapper;
    private boolean status;

    public Bean2DAOImpl(SqlSessionFactory factory) {
        session = factory.openSession();
        mapper = session.getMapper(Bean2Mapper.class);
    }

    @Override
    public boolean add(Bean2 bean) {
        try {
            status = mapper.ins(bean);
            session.commit();
        } catch (Exception e) {
            status = false;
            e.printStackTrace();
        }
        return status;
    }

    @Override
    public boolean mod(Bean2 bean) {
        try {
            status = mapper.upd(bean);
            session.commit();
        } catch (Exception e) {
            status = false;
            e.printStackTrace();
        }
        return status;
    }

    @Override
    public boolean rem(int f6) {
        try {
            status = mapper.del(f6);
            session.commit();
        } catch (Exception e) {
            status = false;
            e.printStackTrace();
        }
        return status;
    }

    @Override
    public WrapBean2 que(int f6) {
        WrapBean2 wb;
        try {
            wb = mapper.a(f6);
        } catch (Exception e) {
            wb = null;
            e.printStackTrace();
        }
        return wb;
    }

    @Override
    public int que(Bean2 bean) {
        int f6;
        try {
            f6 = mapper.b(bean);
        } catch (Exception e) {
            f6 = 0;
            e.printStackTrace();
        }
        return f6;
    }

    @Override
    public int count() {
        int count;
        try {
            count = mapper.c();
        } catch (Exception e) {
            count = -1;
            e.printStackTrace();
        }
        return count;
    }
}
